package com.nbsaas.boot.data.data.entity;


import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.data.ext.domain.ext.QueryTemplateExt;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.filter.Operator;
import com.nbsaas.boot.rest.request.ResultHandle;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;

@ComposeView
@org.hibernate.annotations.Table(appliesTo = "sys_common_query_report", comment = "查询报表")
@Data
@FormAnnotation(title = "查询报表")
@Entity
@Table(name = "sys_common_query_report")
public class QueryReport {

    @SearchItem(label = "模板代码", name = "id", operator = Operator.like, show = false)
    @FormField(title = "报表代码", grid = true, width = "300", col = 22, required = true)
    @Comment("主键id")
    @Id
    @Column(length = 32, unique = true)
    private String id;


    @FormField(title = "报表名称", grid = true, width = "400", col = 22, required = true)
    @SearchItem(label = "报表名称", name = "name")
    @Comment("报表名称")
    String name;


    @FormField(title = "报表内容", width = "400", col = 22)
    @Comment("报表内容")
    String content;

    @Comment("调试模式 调试模式增加sql输出 ")
    private Integer debugModel;

    @Comment("缓存模式 计算请求参数md5，作为缓存键")
    private Integer cacheModel;

    @Comment("日期范围 1当天 2最近七天 3本周  4本月")
    private Integer dateRange;


    @Comment("头部样式 1样式1 2样式2 3样式3  4样式4")
    private Integer headerStyle;


    @Comment("汇总模型")
    private String summaryModel;


    @Comment("是否显示页脚")
    private Integer haveFooter;


    @Column(length = 200)
    @Comment("存储过程")
    private String storeProcedure;


    @Column(length = 100)
    @Comment("存储过程清理")
    private String clearSql;

    @Dict(
            items = {
                    @DictItem(value = 1, label = "表格"),
                    @DictItem(value = 2, label = "分页")
            }
    )
    private Integer displayType;

    @Dict(items = {
            @DictItem(value = 1, label = "执行存储过程"),
            @DictItem(value = 2, label = "不执行存储过程")
    })
    private Integer execType;

    @Dict(
            items = {
                    @DictItem(value = 1, label = "公共查询"),
                    @DictItem(value = 2, label = "私有查询")
            }
    )
    @FormField(title = "报表类型", grid = true, col = 22)
    @SearchItem(label = "报表类型", name = "type", operator = Operator.eq, classType = Integer.class, show = false)
    @Comment("报表类型")
    Integer type;

    @Comment("权限")
    private String permission;


    @Type(type = "io.hypersistence.utils.hibernate.type.json.JsonType")
    @Comment("扩展数据")
    @Column(columnDefinition = "text")
    private QueryTemplateExt extData;


    @Comment("查询结果是否处理 1处理 2不处理")
    private Integer resultHandleType;


    @Type(type = "io.hypersistence.utils.hibernate.type.json.JsonType")
    @Comment("查询结果再处理")
    @Column(columnDefinition = "text")
    private ResultHandle resultHandle;


    @FormField(title = "报表描述", grid = true, width = "200000", col = 22, type = InputType.textarea)
    @Comment("报表描述")
    String note;


    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

    @FormField(title = "添加时间", grid = true, width = "160", ignore = true)
    @Comment("添加时间")
    private Date addDate;

    @Comment("最新修改时间")
    private Date lastDate;


    @Comment("数据范围控制1")
    private Integer dataScope1;

    @Comment("数据范围控制2")
    private Integer dataScope2;

    @Comment("数据范围控制3")
    private Integer dataScope3;


    @Comment("数据范围控制4")
    private Integer dataScope4;

    @Comment("数据范围控制5")
    private Integer dataScope5;

    @Comment("数据范围控制6")
    private Integer dataScope6;


    @Comment("是否是慢查询 1是 2不是")
    private Integer slowQuery;

}
